home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / yacas_alg / yacas_morphos / share / yacas / include / substitute.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  1.9 KB  |  75 lines

  1.  
  2. #ifndef __substitute_h__
  3. #define __substitute_h__
  4.  
  5. #include "yacasbase.h"
  6. #include "lispobject.h"
  7.  
  8.  
  9. /** Behaviour for substituting sub-expressions.
  10.  */
  11. class SubstBehaviourBase : public YacasBase
  12. {
  13. public:
  14.     virtual LispBoolean Matches(LispPtr& aResult, LispPtr& aElement) = 0;
  15. };
  16.  
  17. /** main routine that can perform substituting of expressions
  18.  */
  19. void InternalSubstitute(LispPtr& aTarget, LispPtr& aSource,
  20.                         SubstBehaviourBase& aBehaviour);
  21.  
  22.  
  23. /** Substing one expression for another. The simplest form
  24.  * of substitution
  25.  */
  26. class SubstBehaviour : public SubstBehaviourBase
  27. {
  28. public:
  29.     SubstBehaviour(LispEnvironment& aEnvironment,LispPtr& aToMatch,
  30.                   LispPtr& aToReplaceWith);
  31.     virtual LispBoolean Matches(LispPtr& aResult, LispPtr& aElement);
  32. private:
  33.     LispEnvironment& iEnvironment;
  34.     LispPtr& iToMatch;
  35.     LispPtr& iToReplaceWith;
  36. };
  37.  
  38. /** subst behaviour for changing the local variables to have unique
  39.  * names.
  40.  */
  41. class LocalSymbolBehaviour : public SubstBehaviourBase
  42. {
  43. public:
  44.     LocalSymbolBehaviour(LispStringPtr* aOriginalNames,
  45.                          LispStringPtr* aNewNames, LispInt aNrNames);
  46.     virtual LispBoolean Matches(LispPtr& aResult, LispPtr& aElement);
  47. private:
  48.     LispStringPtr* iOriginalNames;
  49.     LispStringPtr* iNewNames;
  50.     LispInt iNrNames;
  51. };
  52.  
  53. /** subst behaviour for backquote mechanism as in LISP.
  54.  * When typing `(...) all occurrences of @a will be
  55.  * replaced with:
  56.  * 1) a evaluated if a is an atom
  57.  * 2) function call with function name replaced by evaluated
  58.  *    head of function if a is a function. For instance, if
  59.  *    a is f(x) and f is g, then f(x) gets replaced by g(x)
  60.  */
  61. class BackQuoteBehaviour : public SubstBehaviourBase
  62. {
  63. public:
  64.     BackQuoteBehaviour(LispEnvironment& aEnvironment)
  65.         : iEnvironment(aEnvironment) {};
  66.     virtual LispBoolean Matches(LispPtr& aResult, LispPtr& aElement);
  67.     LispEnvironment& iEnvironment;
  68. };
  69.  
  70.  
  71.  
  72.  
  73. #endif
  74.  
  75.